package com.mybatis.handler;

import com.mybatis.constant.Constants;
import com.mybatis.dto.request.CodeGenerationParam;
import com.mybatis.entity.GeneratorCodeLogEntity;
import com.mybatis.service.GeneratorCodeLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @desc: 异步操作类
 * @projectName: mybatis-generator-parent
 * @author: xhs
 * @date: 2023-9-12 012 20:12
 * @version: JDK 1.8
 */
@Slf4j
@Component
public class AsyncGenerator {

    @Resource
    private GeneratorCodeLogService codeLogService;

    /**
     * 记录日志
     *
     * @param codeGenerationParam 数据库连接的参数
     */
    @Async
    public void generatorCodeLog(CodeGenerationParam codeGenerationParam) {
        GeneratorCodeLogEntity entity = new GeneratorCodeLogEntity();
        BeanUtils.copyProperties(codeGenerationParam, entity);
        boolean save = codeLogService.save(entity);
        log.info("{}记录日志:{}{}", Constants.START, save, Constants.END);
    }
}
